package roborally;

import be.kuleuven.cs.som.annotate.Basic;

public class Robot implements IRobot{

	private long X;
	private long Y;
	private int orientation;
	private double energy;
	private double maxEnergy;
	
	public Robot(long x, long y, int orientation, double energy)
	{
		this.X = x;
		this.Y = y;
		this.orientation = orientation;
		this.energy = energy;
		this.maxEnergy = 20000;
	}

	@Override
	@Basic
	public long getX() {
		return X;
	}
	
	private void addX(long amount){
		this.X = X+amount;
	}
	
	private void substractX(long amount){
		this.X = X-amount;
	}

	@Override
	@Basic
	public long getY() {
		return Y;
	}
	
	private void addY(long amount){
		this.Y = Y+amount;
	}
	
	private void substractY(long amount){
		this.Y = Y-amount;
	}

	@Override
	@Basic
	public int getOrientation() {
		return orientation;
	}
	
	private void setOrientation(int direction) {
		this.orientation = direction;
	}

	@Override
	public void move() {
		// TODO Moet veel simpeler, te veel if-testen en moet rekening houden met grootte van het veld, wat nu oneindig is...
		int orientation = getOrientation();
		if(getX()!=0 && getY()!=0){					//if not at the edges of the grid {...}
			if(orientation==1){	addX(1);		}	//move right
			if(orientation==2){	substractX(1);	}	//move down
			if(orientation==3){	addY(1);		} 	//move left
			if(orientation==0){	substractY(1);	}	//move up
		}// close if-loop
		else if(getX()==0 && getY()!=0){			//if on the X-axis but not the origin
			if(orientation==1){	addX(1);		}	//move right
			if(orientation==2){	substractX(1);	}	//move down
			if(orientation==3){	addY(1);		} 	//move left
			if(orientation==0){	}					//CANNOT MOVE UP
		}//close else-if-loop
		else if(getX()!=0 && getY()==0){			//if on the Y-axis but not the origin
			if(orientation==1){	addX(1);		}	//move right
			if(orientation==2){	substractX(1);	}	//move down
			if(orientation==3){	} 					//CANNOT MOVE LEFT
			if(orientation==0){	substractY(1);	}	//move up
		}//close else-if-loop
		else if(getX()==0 && getY()==0){			//if in the origin
			if(orientation==1){	addX(1);		}	//move right
			if(orientation==2){	substractX(1);	}	//move down
			if(orientation==3){ } 					//CANNOT MOVE LEFT
			if(orientation==0){ }					//CANNOT MOVE UP
		}//close else-if-loop
		
	}

	@Override
	public void turnClockwise() {
		int orientation = getOrientation();
		if(orientation==1){	setOrientation(2);	}	//turn from right to bottom
		if(orientation==2){	setOrientation(3);	}	//turn from bottom to left
		if(orientation==3){	setOrientation(0);	} 	//turn from left to top
		if(orientation==0){	setOrientation(1);	}	//turn from top to right
		
	}

	@Override
	@Basic
	public double getEnergy() {
		return energy;
	}

	@Override
	public double getFractionEnergy() {
		return (energy/maxEnergy);
	}

	@Override
	public void recharge(double energyAmount) {
		
	}

	@Override
	public int isGetEnergyRequiredToReachAndMoveNextTo16Plus() {
		return 0;
	}

	@Override
	public double getEnergyRequiredToReach(long x, long y) {
		return 0;
	}

	@Override
	public void moveNextTo(IRobot robot, IRobot robot2) {
		
	}
	
}
